- content_for :javascript do
  initialize_pending_consent_form("#{t("people.new.email_is_in_use_or_not_allowed")}",#{invite_only}, "#{t("people.new.invalid_invitation_code")}");

- content_for :title_header do
  %h1= t('community_memberships.new.join_community', community: @current_community.name(I18n.locale))

- if session[:fb_join] == "pending_analytics"
  - content_for :javascript do
    window.ST.analytics.logEvent('user', "signed up", "facebook");
  - session[:fb_join] = "analytics_reported"

.centered-section
  %p
    - if invite_only && values[:invitation_code].blank?
      = t('community_memberships.new.you_can_join_with_invite_only')
    - elsif !has_valid_email_for_community
      - if allowed_emails.size > 1
        = t('community_memberships.new.you_can_join_email_confirmation_multiple_addresses', email_endings: allowed_emails.join(", "))
      - else
        = t('community_memberships.new.you_can_join_email_confirmation', email_ending: allowed_emails.first)
    - else
      = t('community_memberships.new.welcome_fb_user', name: PersonViewUtils.person_display_name_for_type(@current_user, "first_name_only"))
      = t('community_memberships.new.fb_join_accept_terms')

  %p
    = t('community_memberships.new.if_want_to_view_content')
    = link_to(t('community_memberships.new.log_out'), logout_path) + "."

  = form_tag give_consent_path, id: "pending_consent_form" do

    - if invite_only
      - if values[:invitation_code].present?
        = hidden_field_tag "form[invitation_code]", values[:invitation_code]
      - else
        = label_tag "form[invitation_code", t('people.new.invitation_code'), class: "inline"
        = link_to t('common.what_is_this'), "#", tabindex: "-1", id: "help_invitation_code_link", class: "label-info"
        = text_field_tag "form[invitation_code]", values[:invitation_code], class: :text_field, maxlength: "20"

    - if !has_valid_email_for_community
      = label_tag "form[email]", t('people.new.email'), class: "before_description"
      = text_field_tag "form[email]", values[:email], class: :text_field, maxlenght: "255"

    .outer-checkbox-container
      .checkbox-container
        = check_box_tag "form[consent]", "on", values[:consent] == "on", id: "community_membership_consent"
        = label_tag "form[consent]", class: "checkbox" do
          = raw t('people.new.i_accept_the_terms_and_privacy',
            terms: link_to(t("people.new.terms"), "#", :tabindex => "-1", :id => "terms_link", :class => "form"),
            privacy: link_to(t("people.new.privacy"), "#", :tabindex => "-1", :id => "privacy_link", :class => "form"),)

    .outer-checkbox-container
      .checkbox-container
        = check_box_tag "form[admin_emails_consent]", "on", values[:admin_email_consent] == "on", id: "admin_emails_consent"
        = label_tag "form[admin_emails_consent]", t('people.new.admin_emails_consent'), class: "checkbox"

    - if @service.has_person_custom_fields?
      - @service.custom_field_values.each_with_index do |custom_field_value, index|
        - custom_field = custom_field_value.question
        - custom_field.with_type do |field_type|
          - prefix = "person[custom_field_values_attributes][]"
          .inline-label-container
            = label "person_custom_fields", index, "#{custom_field.name(I18n.locale)}#{custom_field.required ? '*' : ''}",
              class: 'inline'
            - if custom_field.public?
              %small= t('people.new.this_field_will_be_publicly_visible')
          = hidden_field_tag "#{prefix}[id]", custom_field_value.id
          = hidden_field_tag "#{prefix}[type]", custom_field_value.type
          = hidden_field_tag "#{prefix}[custom_field_id]", custom_field_value.custom_field_id
          = render "settings/custom_fields/#{field_type}", :service => @service,
            :custom_field => custom_field, index: index,
            :custom_field_value => custom_field_value,
            :prefix => prefix

    = button_tag(t('community_memberships.new.join_community_button'), class: "send_button")

= render partial: "people/help_texts", collection: ["terms", "help_invitation_code", "privacy"], as: :field
